<template>
  <div class="app-page">
    <el-table-form ref="form">
      <el-form-item class="merge-item">
        <el-select v-model="qType" style="width: 170px; margin-right: 2px;">
          <el-option label="客户名称" value="csmName" />
          <el-option label="客户电话" value="contactPhone" />
          <el-option label="客户编号" value="csmCode" />
          <el-option label="备注" value="remark" />
        </el-select>
        <el-input v-model.trim="csmText" placeholder="请输入" clearable @keyup.enter.native="search" />
      </el-form-item>
      <el-form-item label="单号">
        <el-input v-model.trim="query.orderCode" placeholder="请输入" clearable @keyup.enter.native="search" />
      </el-form-item>
      <el-form-item label="批发类型">
        <el-select v-model="wsaleType" filterable clearable placeholder="请选择">
          <el-option
            v-for="item in wsaleTypeBottleMap"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item :table-form-merge="2" class="merge-item">
        <el-select v-model="query.timeType" style="width: 170px; margin-right: 2px;">
          <el-option label="登记时间" value="1" />
          <el-option label="结单时间" value="2" />
        </el-select>
        <el-date-picker
          v-model="date"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          unlink-panels
          :clearable="false"
        />
      </el-form-item>
      <el-form-item label="责任机构" prop="orgSNNo">
        <el-tree-select
          v-model="query.orgSNNo"
          clearable
          class="tree-select"
          :popover-width="360"
          :select-params="{
            clearable: true,
            placeholder: '请选择',
            loading: $loadingPlugin.getTreeData,
          }"
          :tree-params="{
            'expand-on-click-node': false,
            'highlight-current': true,
            'filterable': true,
            props: {
              value: 'orgSNNo',
              label: 'orgName',
              disabled: 'disabled',
            },
            data: treeData,
          }"
          @node-click="selectTreeChange"
          @select-clear="closeTree"
        />
      </el-form-item>
      <el-form-item class="merge-item">
        <el-select v-model="user_qtype" style="width: 170px; margin-right: 2px;">
          <el-option value="transactId" label="登记人" />
          <el-option value="ownerId" label="结单人" />
        </el-select>
        <el-select
          v-model="user_qtype_value"
          :loading="$loadingPlugin.getOwnerList"
          placeholder="请选择"
        >
          <el-option
            v-for="item in ownerList"
            :key="item.userId"
            :label="item.userName"
            :value="item.userId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="单据状态" prop="orderStatus">
        <el-select v-model="query.orderStatus" filterable clearable placeholder="请选择">
          <el-option
            v-for="item in orderStatusMap"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式">
        <el-select v-model="query.paymentMethod" filterable clearable placeholder="请选择">
          <el-option
            v-for="item in paymentMethodMap"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <template v-slot:btns>
        <el-button
          v-permission="[30302,1]"
          type="primary"
          icon="el-icon-search"
          @click="search"
        >查询</el-button>
      </template>
    </el-table-form>
    <div style="margin-bottom: 10px;" class="btn-group">
      <div>
        <el-button
          v-permission="[30302,2]"
          type="primary"
          icon="el-icon-plus"
          @click="add"
        >新增</el-button>
        <el-button
          v-permission="[30302,7]"
          type="primary"
          icon="el-icon-download"
          @click="exportFile"
        >导出</el-button>
      </div>
      <div style="font-size: 14px; line-height: 32px;">
        <span>实收净重（吨）合计：{{ tableData.totalNetWeight }}</span>&emsp;&emsp;
        <span>盈余量（吨）合计：{{ tableData.weight3 }}</span>&emsp;&emsp;
        <span>订单金额合计：{{ tableData.tReceivables }}</span>
      </div>
    </div>
    <lb-table
      ref="lbTable"
      v-el-height-adaptive-table="{ bottomOffset: 10 }"
      height="250"
      border
      highlight-current-row
      element-loading-text="加载中"
      :column="column"
      :data="tableData.data"
      pagination
      :total="tableData.total"
      :row-class-name="tableRowClassName"
      custom-column
      @fetch="fetchData"
    />
    <statement-bottle ref="statementBottle" />
    <add-lorry-order ref="addlorryorder" />
    <weighing ref="weighing" />
  </div>
</template>

<script>
  import {
    queryOwnersList,
    bottleSalesQueryList,
    saveLorryOrderUpdate,
    wsaleOrderBillprintStatusUpdate,
    queryWsaleOrderBillPayStatus,
    wsaleExport,
    queryExportDomain
  } from '@/api'
  import { mergeAsyncFunc } from '@/utils/mergeAsyncFunc'
  import moment from 'dayjs'
  import { formatColumnMap, parseTime } from '@/utils'
  import getTreeData from '@/utils/jsonTree'
  import { mapGetters } from 'vuex'
  import StatementBottle from './components/StatementBottle'
  import AddLorryOrder from './components/AddLorryOrder'
  import weighing from './components/weighing'
  import { keepDotLength } from '@/utils/math'

  export default {
    name: 'tab-lorry',
    components: {
      StatementBottle,
      AddLorryOrder,
      weighing
    },
    data() {
      return {
        mode: 1,
        actionColWidth: 80,
        treeData: [],
        exportDomain: '',
        wsaleTypeBottleMap: [
          { value: 2, desc: '上门批发', key: 'TYPE2' },
          { value: 3, desc: '代运业务', key: 'TYPE3' }
        ],
        orderStatusMap: [
          { value: 1, desc: '待称重', key: 'WEIGH-1' },
          { value: 2, desc: '未结单', key: 'NOPAY' },
          { value: 10, desc: '已结单', key: 'PAY' },
          { value: 12, desc: '已冲红', key: 'DO' },
          { value: -1, desc: '已作废', key: 'DELETE' }
        ],
        paymentMethodMap: [
          { value: 1, desc: '现金', key: 'MONEY' },
          { value: 2, desc: '微信支付', key: 'WECHAT' },
          { value: 16, desc: '月结', key: 'YJ' },
          { value: 128, desc: '支付宝', key: 'ALIPAY' },
          { value: 256, desc: '预付卡', key: 'CSMCARD' },
          { value: 512, desc: '国志钱包', key: 'ICBCEPAY' },
          { value: 1024, desc: '银行支付', key: 'ICBCPAY' },
          { value: 2048, desc: '门店扫码', key: 'MDPAY' }
        ],
        user_qtype: 'transactId',
        qType: 'csmCode',
        csmText: '',
        wsaleType: '',
        user_qtype_value: '',
        date: [moment().startOf('day'), moment().endOf('day')],
        query: {
          timeType: '1',
          orgSNNo: '',
          orderCode: '',
          orderStatus: '',
          paymentMethod: '',
          wsaleFlag: '2'
        },
        ownerList: [],
        tableData: {
          totalNetWeight: 0,
          weight3: 0,
          tReceivables: 0,
          total: 0,
          data: []
        }
      }
    },
    computed: {
      ...mapGetters(['orgList']),
      column: function() {
        return [
          {
            type: 'index',
            fixed: 'left'
          },
          {
            prop: 'orderCode',
            width: 160,
            label: '单号',
            render: (h, { row }) => (
              <el-link underline={false} onClick={() => this.openDetail(row)}>{row.orderCode}</el-link>
            ),
            fixed: 'left'
          },
          {
            prop: 'csmCode',
            label: '客户编号'
          },
          {
            prop: 'csmName',
            label: '客户名称'
          },
          {
            prop: 'csmAddress',
            width: 200,
            label: '客户地址'
          },
          {
            prop: 'contactPhone',
            width: 100,
            label: '联系电话'
          },
          {
            prop: 'orgName',
            width: 200,
            label: '责任机构'
          },
          {
            prop: 'wsaleType',
            label: '批发类型',
            render: (h, { row }) => (
              <span>
                {row.wsaleType &&
                  formatColumnMap(
                    this.wsaleTypeBottleMap,
                    'value',
                    row.wsaleType,
                    'desc'
                  )}
              </span>
            )
          },
          {
            prop: 'weight1',
            width: 100,
            align: 'right',
            label: '空车重(吨)',
            render: (h, { row }) => (
              <span>{row.weight1 ? (row.weight1 / 1000).toFixed(3) : ''}</span>
            )
          },
          {
            prop: 'weight2',
            width: 100,
            align: 'right',
            label: '实车重(吨)',
            render: (h, { row }) => (
              <span>{row.weight2 ? (row.weight2 / 1000).toFixed(3) : ''}</span>
            )
          },
          {
            prop: 'freightPrice',
            width: 100,
            label: '运费单价'
          },
          {
            prop: 'totalNetWeight',
            align: 'right',
            width: 120,
            label: '实收净重(吨)',
            render: (h, { row }) => (
              <span>
                {row.totalNetWeight ? (row.totalNetWeight / 1000).toFixed(3) : ''}
              </span>
            )
          },
          {
            prop: 'weight3',
            width: 120,
            align: 'right',
            label: '盈余量(吨)',
            render: (h, { row }) => (
              <span>
                {row.weight3 === 0 ? '0.000' : (row.weight3 / 1000).toFixed(3)}
              </span>
            )
          },
          {
            prop: 'tReceivables',
            align: 'right',
            label: '订单金额'
          },
          {
            prop: 'decimalSpare1',
            align: 'right',
            label: '运费'
          },
          {
            prop: 'paymentMethod',
            label: '支付方式',
            render: (h, { row }) => (
              <span>
                {row.paymentMethod === 0
                  ? ''
                  : formatColumnMap(
                      this.paymentMethodMap,
                      'value',
                      row.paymentMethod,
                      'desc'
                    )}
              </span>
            )
          },
          {
            prop: 'tAccReceivable',
            align: 'right',
            label: '支付金额'
          },
          {
            prop: 'transactTime',
            width: 160,
            label: '登记时间',
            render: (h, { row }) => (
              <span>
                {row.transactTime &&
                  parseTime(row.transactTime, '{y}-{m}-{d} {h}:{i}:{s}')}
              </span>
            )
          },
          {
            prop: 'transactor',
            label: '登记人'
          },
          {
            prop: 'weighTime',
            width: 160,
            label: '称重时间',
            render: (h, { row }) => (
              <span>
                {row.weighTime && parseTime(row.weighTime, '{y}-{m}-{d} {h}:{i}:{s}')}
              </span>
            )
          },
          {
            prop: 'weighName',
            label: '称重人'
          },
          {
            prop: 'signDt',
            width: 160,
            label: '结单时间',
            render: (h, { row }) => (
              <span>
                {row.signDt && parseTime(row.signDt, '{y}-{m}-{d} {h}:{i}:{s}')}
              </span>
            )
          },
          {
            prop: 'ownerName',
            label: '结单人'
          },
          {
            prop: 'remark',
            label: '备注'
          },
          {
            prop: 'orderStatus',
            label: '单据状态',
            render: (h, { row }) => (
              <span>
                {row.orderStatus &&
                  formatColumnMap(this.orderStatusMap, 'value', row.orderStatus, 'desc')}
              </span>
            )
          },
          {
            label: '操作',
            align: 'center',
            className: 'action-col',
            fixed: 'right',
            width: this.actionColWidth,
            render: (h, { row, $index }) => {
              return (
                <div>
                  {row.orderStatus === 2 && (
                    <el-link
                    v-permission={[30302, 3]}
                      underline={false}
                      size='mini'
                      onClick={() => this.openStatementBottle(row, $index)}
                    >
                      结单
                    </el-link>
                  )}
                  {(row.orderStatus === 2 || row.orderStatus === 1) && (
                    <el-link
                    v-permission={[30302, 4]}
                      underline={false}
                      size='mini'
                      type='danger'
                      onClick={() => this.del(row, $index)}
                    >
                      作废
                    </el-link>
                  )}
                  {row.orderStatus === 10 && (
                    <el-link
                    v-permission={[30302, 5]}
                      underline={false}
                      size='mini'
                      onClick={() => this.bottleUpdate(row, $index)}
                    >
                      冲红
                    </el-link>
                  )}
                  {(row.orderStatus !== -1 && row.orderStatus !== 2) && (
                    <el-link
                    v-permission={[30302, 6]}
                      underline={false}
                      size='mini'
                      onClick={() => this.groovePrint(row, $index)}
                    >
                      打印
                    </el-link>
                  )}
                     {row.orderStatus === 1 && (
                    <el-link
                    v-permission={[30302, 8]}
                      underline={false}
                      size='mini'
                      onClick={() => this.weighing(row, $index)}
                    >
                      称重
                    </el-link>
                  )}
                </div>
              )
            }
          }
        ]
      }
    },
    async created() {
      await this.getTreeData()
      this.getExportDomain()
    },
    methods: {
      // 获取导出域名
      getExportDomain() {
        mergeAsyncFunc(queryExportDomain)
          .then((res) => {
            this.exportDomain = res.data
          })
      },
      // 获取所属机构数据
      async getTreeData() {
        const data = this.orgList.map((item) => ({
          label: item.name,
          ...item
        }))
        this.treeData = getTreeData(data)
        this.query.orgSNNo = this.treeData[0].orgSNNo
        this.getOwnerList(this.treeData[0].orgId)
      },
      // 选择所属机构,查询登记人/结单人
      selectTreeChange(value) {
        const martchOrg = this.orgList.find((item) => item.orgSNNo === value.orgSNNo)
        this.getOwnerList(martchOrg.orgId)
      },
      closeTree(v) {
        this.user_qtype_value = ''
        this.ownerList = []
      },
      async getOwnerList(orgId) {
        // const b = corpsetting.sp1 >> 2 & 0x01
        const res = await queryOwnersList({
          orgId
        // corpparm1: b
        })
        this.ownerList = res.data
      },
      _getQuery(obj) {
        const query = {}
        for (const key in obj) {
          if (obj.hasOwnProperty(key)) {
            if (obj[key] !== '') {
              query[key] = obj[key]
            }
          }
        }
        return query
      },
      async fetchData({ currentPage, pageSize }) {
        const params = {
          ...this._getQuery(this.query),
          pageIndex: currentPage,
          pageSize
        }
        params[this.qType] = this.csmText
        params.wsaleType = this.wsaleType ? this.wsaleType : '-1'
        if (this.query.timeType === '1') {
          if (this.date && this.date.length === 2) {
            params['transactDtStart'] = moment(this.date[0]).format()
            params['transactDtEnd'] = moment(this.date[1]).format()
            const diff = moment(this.date[1]).diff(moment(this.date[0]), 'days')
            if (diff > 366) {
              this.$message.error('槽批单最大支持查询1年')
              return
            }
          }
        } else {
          if (this.date && this.date.length === 2) {
            params['signDtStart'] = moment(this.date[0]).format()
            params['signDtEnd'] = moment(this.date[1]).format()
            const diff = moment(this.date[1]).diff(moment(this.date[0]), 'days')
            if (diff > 366) {
              this.$message.error('槽批单最大支持查询1年')
              return
            }
          }
        }
        if (this.user_qtype_value) {
          params[this.user_qtype] = this.user_qtype_value
        }
        if (!this.query.orderStatus) {
          params.orderStatus = 0
        }
        if (!this.query.paymentMethod) {
          params['paymentMethod'] = '-1'
        }
        // console.log('入参', params)
        const res = await bottleSalesQueryList(params)
        // console.log('结果', res)
        this.tableData.data = res.data.rows
        if (currentPage === 1) this.tableData.total = res.data.total
        this.tableData.totalNetWeight = keepDotLength(res.data.tag.totalNetWeight / 1000, 5).toFixed(5)
        this.tableData.weight3 = keepDotLength(res.data.tag.weight3 / 1000, 5).toFixed(5)
        this.tableData.tReceivables = res.data.tag.tReceivables
        this.flexColumnWidth()
      },
      // 点击单号
      async openDetail(row) {
        this.$refs.statementBottle.open(row, 'lorry', 1)
      },
      async add() {
        await this.$refs.addlorryorder.open()
        this.reset()
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      async weighing(row) {
        await this.$refs.weighing.open(row)
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      // 点击结单
      async openStatementBottle(row) {
        await this.$refs.statementBottle.open(row, 'lorry')
      },
      // 点击作废
      del(row, index) {
        this.$confirm('确认作废当前槽批单？', '提示', {
          type: 'warning'
        }).then(async() => {
          const { status } = await saveLorryOrderUpdate({
            orderCode: row.orderCode,
            orderStatus: -1
          })
          if (status === 200) {
            this.$message({
              type: 'success',
              message: '作废槽批单成功！'
            })
            this.$refs.lbTable.fetch({ currentPage: 1 })
          }
        })
      },
      // 点击冲红
      bottleUpdate(row) {
        this.$confirm('确认冲红当前槽批单？', '提示', {
          type: 'warning'
        }).then(async() => {
          const { status } = await saveLorryOrderUpdate({
            orderCode: row.orderCode,
            orderStatus: 12
          })
          console.log('ssssss', status)
          if (status === 200) {
            this.$message({
              type: 'success',
              message: '冲红槽批单成功！'
            })
            this.$refs.lbTable.fetch({ currentPage: 1 })
          }
        })
      },
      async groovePrint(row) {
        const params = {
          orderCode: row.orderCode
        }
        const { status, data } = await queryWsaleOrderBillPayStatus(params)
        if (status === 200) {
          // const intSpare = data.intSpare
          // if (intSpare & 0x01) {
          //   this.$message.error('当前槽批单已打印过,不可再次打印')
          //   return
          // }
          this.tryPrint(data, 37)
          this.search()
        }
      },
      tryPrint(row, type) {
        const cache = JSON.parse(localStorage.tp)
        if (!cache) {
          this.$message.warning('请先设置打印模板')
          return
        }
        const temp = cache[type]
        if (!temp) {
          this.$message.warning('请先设置打印模板')
          return
        }
        let printcmd = {
          cmd: 2,
          title: `正在对订单${row.orderCode}进行批发单打印`,
          elements: []
        }
        printcmd = { ...printcmd, ...temp }
        row.printDt = parseTime(row.transactTime, '{y}-{m}-{d} {h}:{i}')
        row.payMethod = ''
        // for (const item in this.paymentMethodMap) {
        //   if ((item & row.paymentMethodMap) > 0) {
        //     row.payMethod += this.paymentMethodMap[item].desc + ','
        //   }
        // }
        this.paymentMethodMap.forEach((item) => {
          if (item.value === row.paymentMethod) {
            row.payMethod += item.desc + ','
          }
        })
        row.payMethod = (row.payMethod || '').replace(/(^,+)|(,+$)/g, '')
        const items = row.orderWsaleOrderDetailInfoList

        row.gasFee1 = 0
        row.gasDesc1 = ''
        const specMap = {}
        for (const i in items) {
          const item = items[i]
          if (item.gtFlag === 1) {
            row.gasFee1 += item.tReceivable
            if (specMap[item.specCode]) {
              specMap[item.specCode].count += item.gCount
            } else {
              specMap[item.specCode || item.goodsCode] = {
                specName: item.specName || item.goodsName,
                count: item.gCount
              }
            }
          }
          item.gdWeight = this.toDecimal(item.gdWeight, 2).toFixed(2)
          item.gPrice = this.toDecimal(item.gPrice, 2).toFixed(2)
          item.netWeight = this.toDecimal(item.netWeight / 1000, 5).toFixed(5)
          item.tReceivable = this.toDecimal(item.tReceivable, 2).toFixed(2)
        }
        for (const code in specMap) {
          const item = specMap[code]
          row.gasDesc1 += `${item.specName}:${item.count}瓶 `
        }
        row.goodsName = items[0].goodsName
        row.gPrice = this.toDecimal(items[0].gPrice, 2).toFixed(2)
        // row.tReceivables = this.toDecimal(items[0].tReceivables, 2).toFixed(2)
        row.otherFee1 =
          (row.decimalSpare4 || 0) - (row.gasFee1 || 0) - (row.decimalSpare1 || 0)
        if (row.gasDesc1.length > 0) {
          row.gasDesc1 = '本次共出库    ' + row.gasDesc1
        }
        row.weight1 = this.toDecimal(row.weight1 / 1000, 5).toFixed(5)
        row.weight2 = this.toDecimal(row.weight2 / 1000, 5).toFixed(5)
        row.totalNetWeight = this.toDecimal(row.totalNetWeight / 1000, 5).toFixed(5)
        row.fee1 = this.toDecimal(row.fee1 / 100, 2).toFixed(2)
        row.fee2 = this.toDecimal(row.fee2 / 100, 2).toFixed(2)
        row.tAccReceivable = this.toDecimal(row.tAccReceivable, 2).toFixed(2)
        row.tReceivables = this.toDecimal(row.tReceivables, 2).toFixed(2)
        row.totalFee1 = this.toDecimal(row.totalFee1 / 100, 2).toFixed(2)
        row.decimalSpare1 = this.toDecimal(row.decimalSpare1 / 100, 2).toFixed(2)
        if (row.fee1 === 0) {
          row.fee1 = ''
        }
        if (row.fee2 === 0) {
          row.fee2 = ''
        }
        if (!window.jCPrint || !window.jCPrint.ws) {
          this.$message.error('打印未连接')
          return
        }
        if (!row.contact) {
          row.contact = ''
        }
        // console.log(printcmd, temp, row, items)
        window.jCPrint.process(printcmd, temp, row, items)
        if (window.jCPrint.firePush(JSON.stringify(printcmd))) {
          this.updatePrintStatus(row)
        } else {
          this.$message.error('打印未连接')
        }
      },
      async updatePrintStatus(row) {
        const params = {
          orderCode: row.orderCode
        }
        const { status } = await wsaleOrderBillprintStatusUpdate(params)
        if (status === 200) {
          this.$message.success('打印指令已发送')
        }
      },
      toDecimal(str, p) {
        var reg = /^(-?\d+)(\.\d+)?$/
        if (reg.test(str)) {
          return parseFloat(str).toFixed(p || 2) * 1
        }
        return 0
      },
      search() {
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      // 导出
      async exportFile() {
        this.$confirm('确定导出数据？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async() => {
          var list = JSON.parse(JSON.stringify(this.column))
          list.pop()
          list.shift()
          const value = {}
          await list.forEach(l => {
            value[l.prop] = l.label
            return value
          })
          // this.query[this.qType] = this.csmText
          // if (this.query.timeType === '1') {
          //   if (this.date && this.date.length === 2) {
          //     this.query['transactDtStart'] = moment(this.date[0]).format()
          //     this.query['transactDtEnd'] = moment(this.date[1]).format()
          //     const diff = moment(this.date[1]).diff(moment(this.date[0]), 'days')
          //     if (diff > 366) {
          //       this.$message.error('槽批单最大支持查询1年')
          //       return
          //     }
          //   }
          // } else {
          //   if (this.date && this.date.length === 2) {
          //     this.query['signDtStart'] = moment(this.date[0]).format()
          //     this.query['signDtEnd'] = moment(this.date[1]).format()
          //     const diff = moment(this.date[1]).diff(moment(this.date[0]), 'days')
          //     if (diff > 366) {
          //       this.$message.error('槽批单最大支持查询1年')
          //       return
          //     }
          //   }
          // }
          const params = {
            ...this._getQuery(this.query)
          }
          params[this.qType] = this.csmText
          params.wsaleType = this.wsaleType ? this.wsaleType : '-1'
          if (this.query.timeType === '1') {
            if (this.date && this.date.length === 2) {
              params['transactDtStart'] = this.date[0]
              params['transactDtEnd'] = this.date[1]
              const diff = moment(this.date[1]).diff(moment(this.date[0]), 'days')
              if (diff > 366) {
                this.$message.error('槽批单最大支持查询1年')
                return
              }
            }
          } else {
            if (this.date && this.date.length === 2) {
              params['signDtStart'] = this.date[0]
              params['signDtEnd'] = this.date[1]
              const diff = moment(this.date[1]).diff(moment(this.date[0]), 'days')
              if (diff > 366) {
                this.$message.error('槽批单最大支持查询1年')
                return
              }
            }
          }
          if (this.user_qtype_value) {
            params[this.user_qtype] = this.user_qtype_value
          }
          if (!this.query.orderStatus) {
            params.orderStatus = 0
          }
          if (!this.query.paymentMethod) {
            params['paymentMethod'] = '-1'
          }
          const query = {
            paramInfo: params,
            kv: value
          }
          await wsaleExport(query).then((res) => {
            window.open(`${this.exportDomain}/page/export/frame?key=${res.data}`, '_blank')
          })
        })
      },
      // 设置行类名
      tableRowClassName({ row }) {
        if (row.orderStatus === -1) {
          // 说明作废
          return 'deleted-row'
        } else if (row.orderStatus === 12) {
          // 说明冲红
          return 'reverse-row'
        }
        return ''
      },
      // 自适应表格列宽
      flexColumnWidth() {
        this.$nextTick(() => {
          let max = 0
          const actionColDom = document.getElementsByClassName('action-col')
          for (let i = 0; i < actionColDom.length; i++) {
            if (actionColDom[i].tagName === 'TD') {
              let width = 20
              const linkDom = actionColDom[i].childNodes[0].childNodes[0].childNodes
              linkDom.forEach((it) => {
                width += it.offsetWidth + 10
              })
              if (width > max) max = width
            }
          }
          this.actionColWidth = max > 60 ? max - 10 : 50
        })
      },
      reset() {
        this.user_qtype = 'transactId'
        this.qType = 'csmCode'
        this.csmText = ''
        this.wsaleType = ''
        this.user_qtype_value = ''
        this.date = [moment().startOf('day'), moment().endOf('day')]
        this.query = {
          timeType: '1',
          orgSNNo: '',
          orderCode: '',
          orderStatus: '',
          paymentMethod: '',
          wsaleFlag: '2'
        }
      },
      searchTest(e) {
        console.log(e)
      }
    }
  }
</script>

<style lang="scss" scoped>
.el-form-item .el-form-item {
  margin-bottom: 0;
}
.merge-item {
  /deep/ .el-form-item__content {
    display: flex;
  }
}
/deep/ .el-table tr.deleted-row {
  background: #ffdfdf;
}
/deep/ .el-table tr.reverse-row {
  background: #F56C6C;
}
</style>
